<?php
/*
Plugin Name: dKret Randomquotes widget
Description: Adds a sidebar widget to display random quotes (needs radom quote or yet another random quote plugin to show up)
Author: J. Kretzschmar
Version: 1.0
Author URI: http://diekretzschmars.de
*/

if (!function_exists('wp_quotes_random') && !function_exists('yarq_display'))
	return;

function widget_dkret_randomquote($args) {
	extract($args);
	$options = get_option('widget_dkret_randomquote');
	$title = empty($options['title']) ? __('Quote','dkret') : $options['title'];
	echo "$before_widget";
	echo "$before_title".$title.$after_title;
	if (function_exists('wp_quotes_random')) wp_quotes_random(); elseif (function_exists('yarq_display')) yarq_display();
	echo "$after_widget";
}

// Admin section
function widget_control_dkret_randomquote() {
 	$options = get_option('widget_dkret_randomquote');
    		
	if ( $_POST['dkret-submit'] ) {

		$options['title'] = strip_tags(stripslashes($_POST['dkret-randomquote-title']));
		update_option('widget_dkret_randomquote', $options);
	}
	
	$title = htmlspecialchars($options['title'], ENT_QUOTES);
	
	// The Box content
	echo '<p style="text-align:right;"><label for="dkret-randomquote-title" />' . __('Title:') . ' <input style="width: 200px;" id="dkret-randomquote-title" name="dkret-randomquote-title" type="text" value="'.$title.'" /></p>';
	echo '<input type="hidden" id="dkret-submit" name="dkret-submit" value="1" />';
}

$widget_ops = array('classname' => 'widget_dkret_randomquote', 'description' => __( "Show a random quote (dkret)", 'dkret') );
wp_register_sidebar_widget('randomquote', __('Random quote','dkret'), 'widget_dkret_randomquote', $widget_ops);
wp_register_widget_control('randomquote', __('Random quote','dkret'), 'widget_control_dkret_randomquote');
?>
